"""
脚本说明!

# by bingfeng at 2022-12-17
#此脚本是一个图形化的渗透测试工具集

"""

import subprocess, sys, argparse

from setting import java8_path, java9_path

parser = argparse.ArgumentParser(prog="BingFengSecGui", usage="冰封工具箱v1.0", description="冰封工具箱常用参数如下:",
                                 epilog="更详细信息见网站:http://www.wangzhuanzhijia.cf")
parser.add_argument("-u", "--url", required="ture", help="需要扫描的网址或者ip地址")
parser.add_argument("-p", "--protocol", default="https", choices=["https", "http"], help="web协议类型: https 或 http")
parser.add_argument("-e", "--network", default="eth0", help="选择扫描使用的网卡: eth0等")

args = parser.parse_args()

if "://" in vars(args)["url"]:
    url_1 = vars(args)["url"].split("://")
    web_protocol = url_1[0]
    url_or_ip = url_1[1]
else:
    web_protocol = vars(args)["protocol"]
    url_or_ip = vars(args)["url"]

url_list = vars(args)["url"].split(".")
len_url_list = len(url_list)
ip = url_or_ip

if len(url_list) == 4:
    for num in url_list:
        if num.isdigit() and 0 <= int(num) <= 255:
            pass
        else:
            dig_ip = subprocess.Popen('dig {0} | grep -A 2 "ANSWER SECTION" | grep {0} | sed "s/	/ /gp" | grep "IN A" | head -n 1 | awk -F "IN A " "{{print \$2}}"'.
                                      format(url_or_ip), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            ip = dig_ip.stdout.read().decode().strip()
            break
else:
    dig_ip = subprocess.Popen('dig {0} | grep -A 2 "ANSWER SECTION" | grep {0} | sed "s/	/ /gp" | grep "IN A" | head -n 1 | awk -F "IN A " "{{print \$2}}"'.
                              format(url_or_ip), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    ip = dig_ip.stdout.read().decode().strip()

eth = vars(args)["network"]

class BingFengSec():

    def btn_1():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)

    def btn_2():
        subprocess.Popen('systemctl restart todeskd && echo " 重启todeskd服务正常 !! " ', shell=True)

    def btn_3():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)

    def btn_4():
        subprocess.Popen('xfce4-terminal --tab -T wafw00f -x bash -c "wafw00f {0}://{1}; echo \'command<--->: wafw00f {0}://{1}\' ; exec /usr/bin/bash"'.format(web_protocol, url_or_ip), shell=True)

    def btn_5():
        subprocess.Popen('xfce4-terminal --tab -T nmap -x bash -c "nmap -sV -sC -p- {0}; echo \'command<--->: nmap -sV -sC -p- {0}\' ; exec /usr/bin/bash"'.format(url_or_ip), shell=True)

    def btn_6():
        subprocess.Popen('xfce4-terminal --tab -T masscan -x bash -c "masscan -p 1-65535 --rate 10000 -e {0} {1}; echo \'command<--->: masscan -p 1-65535 --rate 10000 -e {0} {1}\' ; exec /usr/bin/bash"'.format(eth, ip), shell=True)

    def btn_7():
        subprocess.Popen('xfce4-terminal --tab -T oneforall -x bash -c "python /root/pub_work/software/secure/OneForAll/oneforall.py --target {0} run; echo \'command<--->: python /root/pub_work/software/secure/OneForAll/oneforall.py --target {0} run\' ; exec /usr/bin/bash"'.format(url_or_ip), shell=True)

    def btn_8():
        subprocess.Popen('xfce4-terminal --tab -T dirsearch -x bash -c "python /root/pub_work/software/secure/dirsearch/dirsearch.py -u {0}; echo \'command<--->: python /root/pub_work/software/secure/dirsearch/dirsearch.py -u {0}\' ; exec /usr/bin/bash"'.format(url_or_ip), shell=True)

    def btn_9():
        subprocess.Popen('xfce4-terminal --tab -T whatweb -x bash -c "whatweb {0}; echo \'command<--->: whatweb {0}\' ; exec /usr/bin/bash"'.format(url_or_ip), shell=True)

    def btn_10():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)

    def btn_11():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)

    def btn_12():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)

    def btn_13():
        subprocess.Popen('xfce4-terminal --tab -T software -x bash -c "cd /root/pub_work/software/secure ; ls; echo \'command<--->: ls /root/pub_work/software/secure \' ; exec /usr/bin/bash"', shell=True)
